package com.hermes.action.homepage;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.hermes.biz.common.model.item.ItemPublicDO;
import com.hermes.biz.common.model.message.MessageInfoDO;
import com.hermes.biz.common.util.string.StringUtil;
import com.hermes.biz.service.user.UserMessageService;
import com.hermes.common.action.BaseAction;
import com.hermes.common.util.LoginHelperUtil;
import com.hermes.common.util.ParameterParserUtil;

/**
 * Message-List
 * 
 * @author 
 *
 *
 *
 */
public class MessageListCenter extends BaseAction {

    private static final long  serialVersionUID = 1L;

    private Logger             log              = Logger.getLogger(MessageListCenter.class);

    private UserMessageService userMessageService;

    private ItemPublicDO       result;

    public String              username         = "";

    public boolean             isLogin          = false;

    public long                userid;

    public String              url;

    @Override
    public String execute() {

        //If-Login
        HttpServletRequest request = ServletActionContext.getRequest();
        LoginHelperUtil loginHelper = new LoginHelperUtil(request);
        if (loginHelper.hasLogined()) {
            setLogin(true);
        }

        String userIdStr = ParameterParserUtil.getParameter("userId");
        String msgType = ParameterParserUtil.getParameter("msgt");

        if (StringUtil.isNotBlank(userIdStr) || StringUtil.isNotBlank(msgType)) {
            return SUCCESS;
        }

        long userId = 0;
        int msgTypeNum = 0;
        if (StringUtil.isNumOnly(userIdStr)) {
            userId = Long.parseLong(userIdStr);
            msgTypeNum = Integer.parseInt(msgType);
            List<MessageInfoDO> resultList = userMessageService.getUserMessageByType(userId,
                msgTypeNum);

            if (resultList != null || resultList.size() < 1) {
                return SUCCESS;
            }
            return SUCCESS;
        }
        log.error("");
        return ERROR;
    }

    public ItemPublicDO getResult() {
        return result;
    }

    public void setResult(ItemPublicDO result) {
        this.result = result;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public boolean isLogin() {
        return isLogin;
    }

    public void setLogin(boolean isLogin) {
        this.isLogin = isLogin;
    }

    public long getUserid() {
        return userid;
    }

    public void setUserid(long userid) {
        this.userid = userid;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public UserMessageService getUserMessageService() {
        return userMessageService;
    }

    public void setUserMessageService(UserMessageService userMessageService) {
        this.userMessageService = userMessageService;
    }
}